//
//  LSZALyricBooksViewController.m
//  JKFuYinProject
//
//  Created by 九酷 on 2018/8/7.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LSZALyricBooksViewController.h"
 
@interface LSZALyricBooksViewController ()<UIWebViewDelegate>
{
    UIWebView * WebView;
}
@end

@implementation LSZALyricBooksViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setALyricBooksUI];
}
-(void)setALyricBooksUI
{
    self.view.backgroundColor = [UIColor whiteColor];
    UIView * viewTop = [[UIView alloc]init];
    viewTop.frame = CGRectMake(0, 0, ScreenWidth, NAVIGATION_BAR_HEIGHT);
    viewTop.backgroundColor = redUIColor;
    [self.view addSubview:viewTop];

    UIButton * butCancel = [[UIButton alloc]init];
    [butCancel setImage:[UIImage imageNamed:@"白叉号"] forState:UIControlStateNormal];
    butCancel.frame = CGRectMake(0, STATUS_BAR_HEIGHT, 60, NAVIGATION_BAR_HEIGHT-STATUS_BAR_HEIGHT);
    [butCancel addTarget:self action:@selector(clickCancelALyricBooks) forControlEvents:UIControlEventTouchUpInside];
    [viewTop addSubview:butCancel];

    UILabel * labelTitle = [[UILabel alloc]init];
    labelTitle.textColor = [UIColor whiteColor];
    labelTitle.text = self.titleStr;
    labelTitle.font = FONT_20;
    labelTitle.textAlignment = NSTextAlignmentCenter;
    labelTitle.frame = CGRectMake(CGRectGetMaxX(butCancel.frame), STATUS_BAR_HEIGHT, ScreenWidth-CGRectGetMaxX(butCancel.frame)*2, NAVIGATION_BAR_HEIGHT-STATUS_BAR_HEIGHT);
    [viewTop addSubview:labelTitle];

    NSString *b = [self.imageViewString substringFromIndex:self.imageViewString.length-3];
    if([b isEqualToString:@"gif"]){
        UIImageView * imageView = [[UIImageView alloc]init];
        imageView.frame = CGRectMake(0, NAVIGATION_BAR_HEIGHT, ScreenWidth, self.view.frame.size.height-NAVIGATION_BAR_HEIGHT);
        [imageView sd_setImageWithURL:[NSURL URLWithString:self.imageViewString] placeholderImage:[UIImage imageNamed:@"placeholder"]];
        [self.view addSubview:imageView];
    }else{
        WebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, ScreenWidth, self.view.frame.size.height-NAVIGATION_BAR_HEIGHT)];
        [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]]];
        WebView.scalesPageToFit = YES;
        WebView.multipleTouchEnabled=YES;
        WebView.userInteractionEnabled=YES;
        WebView.delegate = self;
        WebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
        [self.view addSubview:WebView];
    }
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *meta = [NSString stringWithFormat:@"var meta = document.createElement('meta');meta.content='width=device-width,initial-scale=1.0,minimum-scale=.5,maximum-scale=3';meta.name='viewport';document.getElementsByTagName('head')[0].appendChild(meta);"];
    [WebView stringByEvaluatingJavaScriptFromString:meta];
}
-(void)clickCancelALyricBooks
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
